import apis from "@/api/apis.js"
export default {
	namespaced: true,
	state: {
		userInfo: {},
		risk:{},
		card:{},
		gander:'xxxxxxxxxx'
	},
	mutations: {
		setUserInfo(state, newData) {
			state.userInfo = newData
		},
		//获取风险评测结果
		setrisk(state,newdata){
			
			uni.setStorageSync(`Risk`,newdata)
			state.risk=newdata
		},
		//信息认证
		seycard(state,newdata){
			// console.log(newdata,123213)
			state.card=newdata
		}
	},
	actions: {
		//依据token判断用户有没有登陆
		getToken() {
			return new Promise((resolve, reject) => {
				uni.getStorage({
					key: 'token',
					success: function(res) {
						resolve({
							message: 'token获取成功',
							code: 1,
						})
					},
					fail(err) {
						resolve({
							message: 'token获取失败',
							code: 0
						})

					}
				});
			})
		},
		// 获取本地用户id
		getId(context) {
			return new Promise((resolve, reject) => {
				uni.getStorage({
					key: 'id',
					success: function(res) {
						resolve({
							message: 'id获取成功',
							msg: 1,
							data: res.data
						})

					},

					fail(err) {

						resolve({
							message: 'id获取失败',
							msg: 0
						})

					}
				});
			})
		},



		// 手机验证码
		async sendMsg(context, data) {
			const result = await apis.user.sendMsg(data)
			// console.log(result);
		},
		// 注册
		async register(context, data) {
			const result = await apis.user.register(data)
			// console.log(1111111111111,result);
			return result
		},
		// 手机号登陆
		async phoneLogon(context, data) {
			const result = await apis.user.phoneLogon(data)
			return result
		},
		// 账号登陆
		async nameLogon(context, data) {
			const result = await apis.user.nameLogon(data)
			console.log(222222222,result);
			return result
		},
		// 根据id查询用户
		async getUserById(context, data) {
			const result = await apis.user.getUserById(data)
			if (result.code == 200) {
				// 设置用户信息
				context.commit('setUserInfo', result.data)
			}
		},
		//风险评测
		async getrisk(context,data){
			// console.log(data)
			let risk=await apis.user.getrisk(data)
			// console.log(risk.data)
			context.commit(`setrisk`,risk.data)
			
		},
		//实名认证
		async getresult(context,data){
		 let dd= await apis.user.getresult(data)
		  // console.log(dd)
		 context.commit(`seycard`,dd)
		},
		// 修改用户信息
		async userUpdate(context, data) {
			const result = await apis.user.userUpdate(data)
			// console.log(result);
		},
		//获取用户资产
		async getUserWallet(context,data){
			const result = await apis.user.getUserWallet(data)
			return result
		},
		// 钱包充值
		async userCashIn(context,data){
			const result =await apis.user.userCashIn(data)
			return result
		},
		// 提现
		async userCashOut(context,data){
			const result = await apis.user.userCashOut(data)
			return result
		}
	}


}
